package com.landeb.shop.huo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.landeb.shop.R;
import com.landeb.shop.huo.bean.BeanActShopDetail;

import java.util.List;

/**
 * Created by blade on 2016/12/10.
 */

public class ActShopDetailGvAdapter extends BaseAdapter {

    private List<BeanActShopDetail.DataBean.GoodsBean> mList;
    private Context mContext;
    private LayoutInflater mInflater;

    public ActShopDetailGvAdapter(Context context, List<BeanActShopDetail.DataBean.GoodsBean> list) {
        mContext = context;
        mList = list;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {

            convertView = mInflater.inflate(R.layout.item_fraghome_bottom_gridview, parent, false);

            holder = new ViewHolder();
            holder.mImageView = (ImageView) convertView.findViewById(R.id.imgV_item_fragHome_bottom_gridView);
            holder.mTitle = (TextView) convertView.findViewById(R.id.title_item_fragHome_bottom_gridView);
            holder.mPrice = (TextView) convertView.findViewById(R.id.price_item_fragHome_bottom_gridView);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        // TODO: 2016/10/15 用glide加载图片并赋值给      mImageView
        String title = mList.get(position).getTitle();
        holder.mTitle.setText(title);
        String price = mList.get(position).getPrice();
        holder.mPrice.setText("¥" + price);
        String picUrl = mList.get(position).getPic();
        Glide
                .with(mContext)
                .load(picUrl)
                .placeholder(R.drawable.error_pic)
                .error(R.drawable.error_pic)
                .crossFade()
                .into(holder.mImageView);


        return convertView;
    }

    private class ViewHolder {
        private ImageView mImageView; //图标
        private TextView mTitle; //文字
        private TextView mPrice;
    }

}
